package org.example.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jakarta.annotation.Resource;

import okhttp3.*;
import org.example.system.config.properties.BaiiduConfig;
import org.example.system.config.WechatConfig;
import org.example.system.mapper.TenantMapper;
import org.example.system.model.entity.Tenant;
import org.example.system.service.TenantService;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.io.IOException;
import java.net.URLEncoder;

@Service
public class TenantServiceImpl extends ServiceImpl<TenantMapper, Tenant> implements TenantService {


    @Resource
    private TenantMapper tenantMapper;

    @Autowired
    private BaiiduConfig baiiduConfig;

    private static final OkHttpClient HTTP_CLIENT = new OkHttpClient().newBuilder().build();


    private final WechatConfig wechatConfig;

    public TenantServiceImpl(WechatConfig wechatConfig) {
        this.wechatConfig = wechatConfig;
    }

    @Override
    public boolean xiaohu(Integer id) {
        return tenantMapper.xiaohu(id) > 0;
    }

    @Override
    public boolean jiefeng(Integer id) {
        return tenantMapper.jiefeng(id) > 0;
    }

    @Transactional(rollbackFor = Exception.class,readOnly = true,
            propagation = Propagation.SUPPORTS)
    @Override
    public Tenant getTenantByOpenId(String openid) {
        LambdaQueryWrapper<Tenant> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Tenant::getOpenId, openid);
        return tenantMapper.selectOne(wrapper);
    }


}

